package com.my.test.java.two.moredata.datas.share;

import java.sql.Connection;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import com.my.test.java.two.moredata.datas.HDataSource;
import com.my.test.java.two.moredata.datas.rule.DataSourceAg;
import com.my.test.java.two.moredata.datas.rule.IDataSourceRule;
import com.my.test.java.two.moredata.datas.rule.ITableRule;
import com.my.test.java.two.moredata.datas.rule.TableRuleAg;

public class ShareDataSource {
	
	private Map<String,HDataSource> map;
	private IDataSourceRule dataSourceRule;
	private TableRuleAg tableRule;
	private DataSourceAg dataSourceAg;
	
	public ShareDataSource(){}
	public ShareDataSource(Map<String,HDataSource> map){
		this.map = map;
	}
	public ShareDataSource(Map<String,HDataSource> map,
			IDataSourceRule dataSourceRule,TableRuleAg tableRule)
	{
		this.map = map;
		this.dataSourceRule = dataSourceRule;
		this.tableRule = tableRule;
	}
	public ShareDataSource(Map<String,HDataSource> map,
			DataSourceAg dataSourceAg,TableRuleAg tableRule)
	{
		this.map = map;
		this.dataSourceAg = dataSourceAg;
		this.tableRule = tableRule;
	}

	public ShareConnection getConn(){
		Map<String,Connection> connMap = new HashMap<String,Connection>();
		if(null!=map){
			for(Map.Entry<String, HDataSource> m :map.entrySet()){
				connMap.put(m.getKey(), m.getValue().getConnection());
			}
		}
		return new ShareConnection(connMap,tableRule,dataSourceAg);
	}
}
